// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TradingClientApplet.java

package com.boci.clientapp.main;

import com.boci.common.util.CMLogger;
import com.boci.common.util.StringUtil;
import java.awt.HeadlessException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Logger;
import javax.swing.JApplet;

// Referenced classes of package com.boci.clientapp.main:
//            ApplicationService, AppletConfig, ClientAppLoader, MainPanel

public class TradingClientApplet extends JApplet
{

    public TradingClientApplet()
        throws HeadlessException
    {
    }

    public boolean isValidApplet()
    {
        if(AppletConfig.currentApplet == null)
            return true;
        return AppletConfig.currentApplet.equals(this);
    }

    public void init()
    {
        if(isValidApplet())
        {
            if(AppletConfig.currentApplet == null)
                AppletConfig.currentApplet = this;
            if(!AppletConfig.initFlag)
                ClientAppLoader.startup(false, this);
        }
    }

    public void start()
    {
        if(isValidApplet())
            if(AppletConfig.initFlag)
            {
                ApplicationService appServ = ApplicationService.getInstance();
                appServ.refreshUIForApplet(this);
            } else
            {
                AppletConfig.initFlag = true;
            }
    }

    public void stop()
    {
    }

    public void destroy()
    {
        if(AppletConfig.currentApplet == this)
            AppletConfig.currentApplet = null;
    }

    public int invokeTradingScreen(String pMarket, String pCode, String pPrice, String pTransType)
    {
        Logger logger;
        boolean loginFlag = false;
        boolean validSessionFlag = false;
        logger = CMLogger.getInstance();
        if(pMarket == null || pMarket.equals("") || !pMarket.equals("HK") && !pMarket.equals("US"))
            return 1;
        if(pCode == null || pCode.equals(""))
            return 2;
        if(pPrice == null || pPrice.equals(""))
            return 3;
        if(pTransType == null || pTransType.equals("") || !pTransType.equals("BUY") && !pTransType.equals("SELL"))
            return 4;
        ApplicationService appServ;
        appServ = ApplicationService.getInstance();
        loginFlag = appServ.isLogin();
        if(!loginFlag)
            return 5;
        Boolean appletSessionFlag = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {

            public Object run()
            {
                try
                {
                    if(ApplicationService.getInstance().isValidSession())
                        return new Boolean(true);
                }
                catch(Exception e)
                {
                    return new Boolean(false);
                }
                return new Boolean(false);
            }
        }
);
        validSessionFlag = appletSessionFlag.booleanValue();
        if(!validSessionFlag)
            return 5;
        try
        {
            appServ.closeAllDialog();
            appServ.getMainPanel().showTradingPanel(pMarket, pCode, pPrice, pTransType);
            return 0;
        }
        catch(Exception sysEx)
        {
            logger.severe(StringUtil.formatException(sysEx));
        }
        return 99;
    }
}
